package com.xx.springboot.DataStructure.LeetCode.String;

/**
 * Created by xiaoxiunique on 2018-8-21.
 */
public class strStr {
    public int strStr(String haystack, String needle) {
        if (needle == null || needle.length() > haystack.length())
            return -1;

        if(needle.length() == 0)
            return 0;

        for (int i = 0 ; i < haystack.length() ; i++) {
            if (haystack.charAt(i) == needle.charAt(0) && (i + needle.length()) <= haystack.length()) {
                if(haystack.substring(i, i + needle.length()).equals(needle) )
                    return i;
            }
        }
        return -1;
    }

    public static void main(String[] args) {
        System.out.println((new strStr()).strStr("a", "a"));
    }
}
